home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / nt / gr564s.zip / SRC / RCS.C < prev    next >
C/C++ Source or Header  |  1992-09-05  |  44KB  |  1,592 lines

  1. /*
  2.  *                      RCS create/change operation
  3.  */
  4. /* Copyright (C) 1982, 1988, 1989 Walter Tichy
  5.    Copyright 1990, 1991, 1992 by Paul Eggert
  6.    Distributed under license by the Free Software Foundation, Inc.
  7.  
  8. This file is part of RCS.
  9.  
  10. RCS is free software; you can redistribute it and/or modify
  11. it under the terms of the GNU General Public License as published by
  12. the Free Software Foundation; either version 2, or (at your option)
  13. any later version.
  14.  
  15. RCS is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18. GNU General Public License for more details.
  19.  
  20. You should have received a copy of the GNU General Public License
  21. along with RCS; see the file COPYING.  If not, write to
  22. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  
  24. Report problems and direct all questions to:
  25.  
  26.     rcs-bugs@cs.purdue.edu
  27.  
  28. */
  29.  
  30.  
  31.  
  32.  
  33. /* $Log: rcs.c,v $
  34.  * Revision 5.16  1992/07/28  16:12:44  eggert
  35.  * rcs -l now asks whether you want to break the lock.
  36.  * Add -V.  Set RCS file's mode and time at right moment.
  37.  *
  38.  * Revision 5.15  1992/02/17  23:02:20  eggert
  39.  * Add -T.
  40.  *
  41.  * Revision 5.14  1992/01/27  16:42:53  eggert
  42.  * Add -M.  Avoid invoking umask(); it's one less thing to configure.
  43.  * Add support for bad_creat0.  lint -> RCS_lint
  44.  *
  45.  * Revision 5.13  1992/01/06  02:42:34  eggert
  46.  * Avoid changing RCS file in common cases where no change can occur.
  47.  *
  48.  * Revision 5.12  1991/11/20  17:58:08  eggert
  49.  * Don't read the delta tree from a nonexistent RCS file.
  50.  *
  51.  * Revision 5.11  1991/10/07  17:32:46  eggert
  52.  * Remove lint.
  53.  *
  54.  * Revision 5.10  1991/08/19  23:17:54  eggert
  55.  * Add -m, -r$, piece tables.  Revision separator is `:', not `-'.  Tune.
  56.  *
  57.  * Revision 5.9  1991/04/21  11:58:18  eggert
  58.  * Add -x, RCSINIT, MS-DOS support.
  59.  *
  60.  * Revision 5.8  1991/02/25  07:12:38  eggert
  61.  * strsave -> str_save (DG/UX name clash)
  62.  * 0444 -> S_IRUSR|S_IRGRP|S_IROTH for portability
  63.  *
  64.  * Revision 5.7  1990/12/18  17:19:21  eggert
  65.  * Fix bug with multiple -n and -N options.
  66.  *
  67.  * Revision 5.6  1990/12/04  05:18:40  eggert
  68.  * Use -I for prompts and -q for diagnostics.
  69.  *
  70.  * Revision 5.5  1990/11/11  00:06:35  eggert
  71.  * Fix `rcs -e' core dump.
  72.  *
  73.  * Revision 5.4  1990/11/01  05:03:33  eggert
  74.  * Add -I and new -t behavior.  Permit arbitrary data in logs.
  75.  *
  76.  * Revision 5.3  1990/10/04  06:30:16  eggert
  77.  * Accumulate exit status across files.
  78.  *
  79.  * Revision 5.2  1990/09/04  08:02:17  eggert
  80.  * Standardize yes-or-no procedure.
  81.  *
  82.  * Revision 5.1  1990/08/29  07:13:51  eggert
  83.  * Remove unused setuid support.  Clean old log messages too.
  84.  *
  85.  * Revision 5.0  1990/08/22  08:12:42  eggert
  86.  * Don't lose names when applying -a option to multiple files.
  87.  * Remove compile-time limits; use malloc instead.  Add setuid support.
  88.  * Permit dates past 1999/12/31.  Make lock and temp files faster and safer.
  89.  * Ansify and Posixate.  Add -V.  Fix umask bug.  Make linting easier.  Tune.
  90.  * Yield proper exit status.  Check diff's output.
  91.  *
  92.  * Revision 4.11  89/05/01  15:12:06  narten
  93.  * changed copyright header to reflect current distribution rules
  94.  * 
  95.  * Revision 4.10  88/11/08  16:01:54  narten
  96.  * didn't install previous patch correctly
  97.  * 
  98.  * Revision 4.9  88/11/08  13:56:01  narten
  99.  * removed include <sysexits.h> (not needed)
  100.  * minor fix for -A option
  101.  * 
  102.  * Revision 4.8  88/08/09  19:12:27  eggert
  103.  * Don't access freed storage.
  104.  * Use execv(), not system(); yield proper exit status; remove lint.
  105.  * 
  106.  * Revision 4.7  87/12/18  11:37:17  narten
  107.  * lint cleanups (Guy Harris)
  108.  * 
  109.  * Revision 4.6  87/10/18  10:28:48  narten
  110.  * Updating verison numbers. Changes relative to 1.1 are actually 
  111.  * relative to 4.3
  112.  * 
  113.  * Revision 1.4  87/09/24  13:58:52  narten
  114.  * Sources now pass through lint (if you ignore printf/sprintf/fprintf 
  115.  * warnings)
  116.  * 
  117.  * Revision 1.3  87/03/27  14:21:55  jenkins
  118.  * Port to suns
  119.  * 
  120.  * Revision 1.2  85/12/17  13:59:09  albitz
  121.  * Changed setstate to rcs_setstate because of conflict with random.o.
  122.  * 
  123.  * Revision 4.3  83/12/15  12:27:33  wft
  124.  * rcs -u now breaks most recent lock if it can't find a lock by the caller.
  125.  * 
  126.  * Revision 4.2  83/12/05  10:18:20  wft
  127.  * Added conditional compilation for sending mail.
  128.  * Alternatives: V4_2BSD, V6, USG, and other.
  129.  * 
  130.  * Revision 4.1  83/05/10  16:43:02  wft
  131.  * Simplified breaklock(); added calls to findlock() and getcaller().
  132.  * Added option -b (default branch). Updated -s and -w for -b.
  133.  * Removed calls to stat(); now done by pairfilenames().
  134.  * Replaced most catchints() calls with restoreints().
  135.  * Removed check for exit status of delivermail().
  136.  * Directed all interactive output to stderr.
  137.  * 
  138.  * Revision 3.9.1.1  83/12/02  22:08:51  wft
  139.  * Added conditional compilation for 4.2 sendmail and 4.1 delivermail.
  140.  * 
  141.  * Revision 3.9  83/02/15  15:38:39  wft
  142.  * Added call to fastcopy() to copy remainder of RCS file.
  143.  *
  144.  * Revision 3.8  83/01/18  17:37:51  wft
  145.  * Changed sendmail(): now uses delivermail, and asks whether to break the lock.
  146.  *
  147.  * Revision 3.7  83/01/15  18:04:25  wft
  148.  * Removed putree(); replaced with puttree() in rcssyn.c.
  149.  * Combined putdellog() and scanlogtext(); deleted putdellog().
  150.  * Cleaned up diagnostics and error messages. Fixed problem with
  151.  * mutilated files in case of deletions in 2 files in a single command.
  152.  * Changed marking of selector from 'D' to DELETE.
  153.  *
  154.  * Revision 3.6  83/01/14  15:37:31  wft
  155.  * Added ignoring of interrupts while new RCS file is renamed;
  156.  * Avoids deletion of RCS files by interrupts.
  157.  *
  158.  * Revision 3.5  82/12/10  21:11:39  wft
  159.  * Removed unused variables, fixed checking of return code from diff,
  160.  * introduced variant COMPAT2 for skipping Suffix on -A files.
  161.  *
  162.  * Revision 3.4  82/12/04  13:18:20  wft
  163.  * Replaced getdelta() with gettree(), changed breaklock to update
  164.  * field lockedby, added some diagnostics.
  165.  *
  166.  * Revision 3.3  82/12/03  17:08:04  wft
  167.  * Replaced getlogin() with getpwuid(), flcose() with ffclose(),
  168.  * /usr/ucb/Mail with macro MAIL. Removed handling of Suffix (-x).
  169.  * fixed -u for missing revno. Disambiguated structure members.
  170.  *
  171.  * Revision 3.2  82/10/18  21:05:07  wft
  172.  * rcs -i now generates a file mode given by the umask minus write permission;
  173.  * otherwise, rcs keeps the mode, but removes write permission.
  174.  * I added a check for write error, fixed call to getlogin(), replaced
  175.  * curdir() with getfullRCSname(), cleaned up handling -U/L, and changed
  176.  * conflicting, long identifiers.
  177.  *
  178.  * Revision 3.1  82/10/13  16:11:07  wft
  179.  * fixed type of variables receiving from getc() (char -> int).
  180.  */
  181.  
  182.  
  183. #include "rcsbase.h"
  184.  
  185. struct  Lockrev {
  186.     char const *revno;
  187.         struct  Lockrev   * nextrev;
  188. };
  189.  
  190. struct  Symrev {
  191.     char const *revno;
  192.     char const *ssymbol;
  193.         int     override;
  194.         struct  Symrev  * nextsym;
  195. };
  196.  
  197. struct Message {
  198.     char const *revno;
  199.     struct cbuf message;
  200.     struct Message *nextmessage;
  201. };
  202.  
  203. struct  Status {
  204.     char const *revno;
  205.     char const *status;
  206.         struct  Status  * nextstatus;
  207. };
  208.  
  209. enum changeaccess {append, erase};
  210. struct chaccess {
  211.     char const *login;
  212.     enum changeaccess command;
  213.     struct chaccess *nextchaccess;
  214. };
  215.  
  216. struct delrevpair {
  217.     char const *strt;
  218.     char const *end;
  219.         int     code;
  220. };
  221.  
  222. static int breaklock P((struct hshentry const*));
  223. static int buildeltatext P((struct hshentries const*));
  224. static int doaccess P((void));
  225. static int doassoc P((void));
  226. static int dolocks P((void));
  227. static int domessages P((void));
  228. static int rcs_setstate P((char const*,char const*));
  229. static int removerevs P((void));
  230. static int sendmail P((char const*,char const*));
  231. static int setlock P((char const*));
  232. static struct Lockrev *rmnewlocklst P((struct Lockrev const*));
  233. static void buildtree P((void));
  234. static void cleanup P((void));
  235. static void getaccessor P((char*,enum changeaccess));
  236. static void getassoclst P((int,char*));
  237. static void getchaccess P((char const*,enum changeaccess));
  238. static void getdelrev P((char*));
  239. static void getmessage P((char*));
  240. static void getstates P((char*));
  241. static void scanlogtext P((struct hshentry*,int));
  242.  
  243. static struct buf numrev;
  244. static char const *headstate;
  245. static int chgheadstate, exitstatus, lockhead, unlockcaller;
  246. static int suppress_mail;
  247. static struct Lockrev *newlocklst, *rmvlocklst;
  248. static struct Message *messagelst, **nextmessage;
  249. static struct Status *statelst, **nextstate;
  250. static struct Symrev *assoclst, **nextassoc;
  251. static struct chaccess *chaccess, **nextchaccess;
  252. static struct delrevpair delrev;
  253. static struct hshentry *cuthead, *cuttail, *delstrt;
  254. static struct hshentries *gendeltas;
  255.  
  256. mainProg(rcsId, "rcs", "$Id: rcs.c,v 5.16 1992/07/28 16:12:44 eggert Exp $")
  257. {
  258.     static char const cmdusage[] =
  259.         "\nrcs usage: rcs -{ae}logins -Afile -{blu}[rev] -cstring -{iILqU} -ksubst -mrev:msg -{nN}name[:[rev]] -orange -sstate[:rev] -t[text] -Vn -xsuff file ...";
  260.  
  261.     char *a, **newargv, *textfile;
  262.     char const *branchsym, *commsyml;
  263.     int argc_min, branchflag, changed, expmode, initflag;
  264.     int strictlock, strict_selected, textflag;
  265.     int keepRCStime, Ttimeflag;
  266.     size_t commsymlen;
  267.     struct buf branchnum;
  268.         struct  Lockrev *curlock,  * rmvlock, *lockpt;
  269.         struct  Status  * curstate;
  270.  
  271.     nosetid();
  272.  
  273.     nextassoc = &assoclst;
  274.     nextchaccess = &chaccess;
  275.     nextmessage = &messagelst;
  276.     nextstate = &statelst;
  277.     argc_min = 1;
  278.     branchsym = commsyml = textfile = nil;
  279.     branchflag = strictlock = false;
  280.     bufautobegin(&branchnum);
  281.     commsymlen = 0;
  282.     curlock = rmvlock = nil;
  283.     expmode = -1;
  284.     suffixes = X_DEFAULT;
  285.         initflag= textflag = false;
  286.         strict_selected = 0;
  287.     Ttimeflag = false;
  288.  
  289.         /*  preprocessing command options    */
  290.     argc = getRCSINIT(argc, argv, &newargv);
  291.     argv = newargv;
  292.     while (a = *++argv,  0<--argc && *a++=='-') {
  293.         switch (*a++) {
  294.  
  295.         case 'i':   /*  initial version  */
  296.                         initflag = true;
  297.                         break;
  298.  
  299.                 case 'b':  /* change default branch */
  300.             if (branchflag) redefined('b');
  301.                         branchflag= true;
  302.             branchsym = a;
  303.                         break;
  304.  
  305.                 case 'c':   /*  change comment symbol   */
  306.             if (commsyml) redefined('c');
  307.             commsyml = a;
  308.             commsymlen = strlen(a);
  309.                         break;
  310.  
  311.                 case 'a':  /*  add new accessor   */
  312.             getaccessor(*argv+1, append);
  313.                         break;
  314.  
  315.                 case 'A':  /*  append access list according to accessfile  */
  316.             if (!*a) {
  317.                 error("missing pathname after -A");
  318.                             break;
  319.                         }
  320.             *argv = a;
  321.             if (0 < pairnames(1,argv,rcsreadopen,true,false)) {
  322.                 while (AccessList) {
  323.                 getchaccess(str_save(AccessList->login),append);
  324.                 AccessList = AccessList->nextaccess;
  325.                 }
  326.                 Izclose(&finptr);
  327.                         }
  328.                         break;
  329.  
  330.                 case 'e':    /*  remove accessors   */
  331.             getaccessor(*argv+1, erase);
  332.                         break;
  333.  
  334.                 case 'l':    /*   lock a revision if it is unlocked   */
  335.             if (!*a) {
  336.                 /* Lock head or default branch.  */
  337.                             lockhead = true;
  338.                             break;
  339.                         }
  340.             lockpt = talloc(struct Lockrev);
  341.             lockpt->revno = a;
  342.                         lockpt->nextrev = nil;
  343.                         if ( curlock )
  344.                             curlock->nextrev = lockpt;
  345.                         else
  346.                             newlocklst = lockpt;
  347.                         curlock = lockpt;
  348.                         break;
  349.  
  350.                 case 'u':   /*  release lock of a locked revision   */
  351.             if (!*a) {
  352.                             unlockcaller=true;
  353.                             break;
  354.                         }
  355.             lockpt = talloc(struct Lockrev);
  356.             lockpt->revno = a;
  357.                         lockpt->nextrev = nil;
  358.                         if (rmvlock)
  359.                             rmvlock->nextrev = lockpt;
  360.                         else
  361.                             rmvlocklst = lockpt;
  362.                         rmvlock = lockpt;
  363.  
  364.                         curlock = rmnewlocklst(lockpt);
  365.                         break;
  366.  
  367.                 case 'L':   /*  set strict locking */
  368.             if (strict_selected) {
  369.                if (!strictlock)      /* Already selected -U? */
  370.                    warn("-L overrides -U.");
  371.                         }
  372.                         strictlock = true;
  373.             strict_selected = true;
  374.                         break;
  375.  
  376.                 case 'U':   /*  release strict locking */
  377.             if (strict_selected) {
  378.                if (strictlock)      /* Already selected -L? */
  379.                    warn("-L overrides -U.");
  380.                         }
  381.             strict_selected = true;
  382.                         break;
  383.  
  384.                 case 'n':    /*  add new association: error, if name exists */
  385.             if (!*a) {
  386.                 error("missing symbolic name after -n");
  387.                             break;
  388.                         }
  389.                         getassoclst(false, (*argv)+1);
  390.                         break;
  391.  
  392.                 case 'N':   /*  add or change association   */
  393.             if (!*a) {
  394.                 error("missing symbolic name after -N");
  395.                             break;
  396.                         }
  397.                         getassoclst(true, (*argv)+1);
  398.                         break;
  399.  
  400.         case 'm':   /*  change log message  */
  401.             getmessage(a);
  402.             break;
  403.  
  404.         case 'M':   /*  do not send mail */
  405.             suppress_mail = true;
  406.             break;
  407.  
  408.         case 'o':   /*  delete revisions  */
  409.             if (delrev.strt) redefined('o');
  410.             if (!*a) {
  411.                 error("missing revision range after -o");
  412.                             break;
  413.                         }
  414.                         getdelrev( (*argv)+1 );
  415.                         break;
  416.  
  417.                 case 's':   /*  change state attribute of a revision  */
  418.             if (!*a) {
  419.                 error("state missing after -s");
  420.                             break;
  421.                         }
  422.                         getstates( (*argv)+1);
  423.                         break;
  424.  
  425.                 case 't':   /*  change descriptive text   */
  426.                         textflag=true;
  427.             if (*a) {
  428.                 if (textfile) redefined('t');
  429.                 textfile = a;
  430.                         }
  431.                         break;
  432.  
  433.         case 'T':  /*  do not update last-mod time for minor changes */
  434.             if (*a)
  435.                 goto unknown;
  436.             Ttimeflag = true;
  437.             break;
  438.  
  439.         case 'I':
  440.             interactiveflag = true;
  441.             break;
  442.  
  443.                 case 'q':
  444.                         quietflag = true;
  445.                         break;
  446.  
  447.         case 'x':
  448.             suffixes = a;
  449.             break;
  450.  
  451.         case 'V':
  452.             argc_min = setRCSversion(*argv);
  453.             break;
  454.  
  455.         case 'k':    /*  set keyword expand mode  */
  456.             if (0 <= expmode) redefined('k');
  457.             if (0 <= (expmode = str2expmode(a)))
  458.                 break;
  459.             /* fall into */
  460.                 default:
  461.         unknown:
  462.             faterror("unknown option: %s%s", *argv, cmdusage);
  463.                 };
  464.         }  /* end processing of options */
  465.  
  466.     if (argc < argc_min) faterror("no input file%s", cmdusage);
  467.         if (nerror) {
  468.         diagnose("%s aborted\n",cmdid);
  469.         exitmain(EXIT_FAILURE);
  470.         }
  471.  
  472.     /* Now handle all pathnames.  */
  473.     for (;  0 < argc;  cleanup(), ++argv, --argc) {
  474.     ffree();
  475.  
  476.         if ( initflag ) {
  477.         switch (pairnames(argc, argv, rcswriteopen, false, false)) {
  478.                 case -1: break;        /*  not exist; ok */
  479.                 case  0: continue;     /*  error         */
  480.         case  1: error("file %s exists already", RCSname);
  481.                          continue;
  482.             }
  483.     }
  484.         else  {
  485.         switch (pairnames(argc, argv, rcswriteopen, true, false)) {
  486.                 case -1: continue;    /*  not exist      */
  487.                 case  0: continue;    /*  errors         */
  488.                 case  1: break;       /*  file exists; ok*/
  489.             }
  490.     }
  491.  
  492.  
  493.     /*
  494.      * RCSname contains the name of the RCS file, and
  495.      * workname contains the name of the working file.
  496.          * if !initflag, finptr contains the file descriptor for the
  497.          * RCS file. The admin node is initialized.
  498.          */
  499.  
  500.     diagnose("RCS file: %s\n", RCSname);
  501.  
  502.     changed = initflag;
  503.     keepRCStime = Ttimeflag;
  504.     if (!initflag) {
  505.         if (!checkaccesslist()) continue;
  506.         gettree(); /* Read the delta tree.  */
  507.     }
  508.  
  509.         /*  update admin. node    */
  510.     if (strict_selected) {
  511.         changed  |=  StrictLocks ^ strictlock;
  512.         StrictLocks = strictlock;
  513.     }
  514.     if (
  515.         commsyml &&
  516.         (
  517.         commsymlen != Comment.size ||
  518.         memcmp(commsyml, Comment.string, commsymlen) != 0
  519.         )
  520.     ) {
  521.         Comment.string = commsyml;
  522.         Comment.size = strlen(commsyml);
  523.         changed = true;
  524.     }
  525.     if (0 <= expmode  &&  Expand != expmode) {
  526.         Expand = expmode;
  527.         changed = true;
  528.     }
  529.  
  530.         /* update default branch */
  531.     if (branchflag && expandsym(branchsym, &branchnum)) {
  532.         if (countnumflds(branchnum.string)) {
  533.         if (cmpnum(Dbranch, branchnum.string) != 0) {
  534.             Dbranch = branchnum.string;
  535.             changed = true;
  536.         }
  537.             } else
  538.         if (Dbranch) {
  539.             Dbranch = nil;
  540.             changed = true;
  541.         }
  542.     }
  543.  
  544.     changed |= doaccess();    /* Update access list.  */
  545.  
  546.     changed |= doassoc();    /* Update association list.  */
  547.  
  548.     changed |= dolocks();    /* Update locks.  */
  549.  
  550.     changed |= domessages();    /* Update log messages.  */
  551.  
  552.         /*  update state attribution  */
  553.         if (chgheadstate) {
  554.             /* change state of default branch or head */
  555.             if (Dbranch==nil) {
  556.                 if (Head==nil)
  557.              warn("can't change states in an empty tree");
  558.         else if (strcmp(Head->state, headstate) != 0) {
  559.             Head->state = headstate;
  560.             changed = true;
  561.         }
  562.         } else
  563.         changed |= rcs_setstate(Dbranch,headstate);
  564.         }
  565.     for (curstate = statelst;  curstate;  curstate = curstate->nextstatus)
  566.         changed |= rcs_setstate(curstate->revno,curstate->status);
  567.  
  568.         cuthead = cuttail = nil;
  569.     if (delrev.strt && removerevs()) {
  570.             /*  rebuild delta tree if some deltas are deleted   */
  571.             if ( cuttail )
  572.         VOID genrevs(cuttail->num, (char *)nil,(char *)nil,
  573.                  (char *)nil, &gendeltas);
  574.             buildtree();
  575.         changed = true;
  576.         keepRCStime = false;
  577.         }
  578.  
  579.     if (nerror)
  580.         continue;
  581.  
  582.     putadmin();
  583.         if ( Head )
  584.            puttree(Head, frewrite);
  585.     putdesc(textflag,textfile);
  586.  
  587.         if ( Head) {
  588.         if (delrev.strt || messagelst) {
  589.         if (!cuttail || buildeltatext(gendeltas)) {
  590.             advise_access(finptr, MADV_SEQUENTIAL);
  591.             scanlogtext((struct hshentry *)nil, false);
  592.                     /* copy rest of delta text nodes that are not deleted      */
  593.             changed = true;
  594.         }
  595.             }
  596.         }
  597.  
  598.     if (initflag) {
  599.         /* Adjust things for donerewrite's sake.  */
  600.         if (stat(workname, &RCSstat) != 0) {
  601. #            if bad_creat0
  602.             mode_t m = umask(0);
  603.             (void) umask(m);
  604.             RCSstat.st_mode = (S_IRUSR|S_IRGRP|S_IROTH) & ~m;
  605. #            else
  606.             changed = -1;
  607. #            endif
  608.         }
  609.         RCSstat.st_nlink = 0;
  610.         keepRCStime = false;
  611.     }
  612.     if (donerewrite(changed, keepRCStime) != 0)
  613.         break;
  614.  
  615.     diagnose("done\n");
  616.     }
  617.  
  618.     tempunlink();
  619.     exitmain(exitstatus);
  620. }       /* end of main (rcs) */
  621.  
  622.     static void
  623. cleanup()
  624. {
  625.     if (nerror) exitstatus = EXIT_FAILURE;
  626.     Izclose(&finptr);
  627.     Ozclose(&fcopy);
  628.     ORCSclose();
  629.     dirtempunlink();
  630. }
  631.  
  632.     exiting void
  633. exiterr()
  634. {
  635.     dirtempunlink();
  636.     tempunlink();
  637.     _exit(EXIT_FAILURE);
  638. }
  639.  
  640.  
  641.     static void
  642. getassoclst(flag, sp)
  643. int     flag;
  644. char    * sp;
  645. /*  Function:   associate a symbolic name to a revision or branch,      */
  646. /*              and store in assoclst                                   */
  647.  
  648. {
  649.         struct   Symrev  * pt;
  650.     char const *temp;
  651.         int                c;
  652.  
  653.     while ((c = *++sp) == ' ' || c == '\t' || c =='\n')
  654.         continue;
  655.         temp = sp;
  656.     sp = checksym(sp, ':');  /*  check for invalid symbolic name  */
  657.     c = *sp;   *sp = '\0';
  658.         while( c == ' ' || c == '\t' || c == '\n')  c = *++sp;
  659.  
  660.         if ( c != ':' && c != '\0') {
  661.         error("invalid string %s after option -n or -N",sp);
  662.             return;
  663.         }
  664.  
  665.     pt = talloc(struct Symrev);
  666.         pt->ssymbol = temp;
  667.         pt->override = flag;
  668.     if (c == '\0')  /*  delete symbol  */
  669.             pt->revno = nil;
  670.         else {
  671.         while ((c = *++sp) == ' ' || c == '\n' || c == '\t')
  672.         continue;
  673.         pt->revno = sp;
  674.         }
  675.         pt->nextsym = nil;
  676.     *nextassoc = pt;
  677.     nextassoc = &pt->nextsym;
  678. }
  679.  
  680.  
  681.     static void
  682. getchaccess(login, command)
  683.     char const *login;
  684.     enum changeaccess command;
  685. {
  686.     register struct chaccess *pt;
  687.  
  688.     pt = talloc(struct chaccess);
  689.     pt->login = login;
  690.     pt->command = command;
  691.     pt->nextchaccess = nil;
  692.     *nextchaccess = pt;
  693.     nextchaccess = &pt->nextchaccess;
  694. }
  695.  
  696.  
  697.  
  698.     static void
  699. getaccessor(opt, command)
  700.     char *opt;
  701.     enum changeaccess command;
  702. /*   Function:  get the accessor list of options -e and -a,     */
  703. /*        and store in chaccess                */
  704.  
  705.  
  706. {
  707.         register c;
  708.     register char *sp;
  709.  
  710.     sp = opt;
  711.     while ((c = *++sp) == ' ' || c == '\n' || c == '\t' || c == ',')
  712.         continue;
  713.         if ( c == '\0') {
  714.         if (command == erase  &&  sp-opt == 1) {
  715.         getchaccess((char const*)nil, command);
  716.         return;
  717.         }
  718.         error("missing login name after option -a or -e");
  719.         return;
  720.         }
  721.  
  722.         while( c != '\0') {
  723.         getchaccess(sp, command);
  724.         sp = checkid(sp,',');
  725.         c = *sp;   *sp = '\0';
  726.                 while( c == ' ' || c == '\n' || c == '\t'|| c == ',')c =(*++sp);
  727.         }
  728. }
  729.  
  730.  
  731.     static void
  732. getmessage(option)
  733.     char *option;
  734. {
  735.     struct Message *pt;
  736.     struct cbuf cb;
  737.     char *m;
  738.  
  739.     if (!(m = strchr(option, ':'))) {
  740.         error("-m option lacks revision number");
  741.         return;
  742.     }
  743.     *m++ = 0;
  744.     cb = cleanlogmsg(m, strlen(m));
  745.     if (!cb.size) {
  746.         error("-m option lacks log message");
  747.         return;
  748.     }
  749.     pt = talloc(struct Message);
  750.     pt->revno = option;
  751.     pt->message = cb;
  752.     pt->nextmessage = 0;
  753.     *nextmessage = pt;
  754.     nextmessage = &pt->nextmessage;
  755. }
  756.  
  757.  
  758.     static void
  759. getstates(sp)
  760. char    *sp;
  761. /*   Function:  get one state attribute and the corresponding   */
  762. /*              revision and store in statelst                  */
  763.  
  764. {
  765.     char const *temp;
  766.         struct  Status  *pt;
  767.         register        c;
  768.  
  769.     while ((c = *++sp) ==' ' || c == '\t' || c == '\n')
  770.         continue;
  771.         temp = sp;
  772.     sp = checkid(sp,':');  /* check for invalid state attribute */
  773.     c = *sp;   *sp = '\0';
  774.         while( c == ' ' || c == '\t' || c == '\n' )  c = *++sp;
  775.  
  776.         if ( c == '\0' ) {  /*  change state of def. branch or Head  */
  777.             chgheadstate = true;
  778.             headstate  = temp;
  779.             return;
  780.         }
  781.         else if ( c != ':' ) {
  782.         error("missing ':' after state in option -s");
  783.             return;
  784.         }
  785.  
  786.     while ((c = *++sp) == ' ' || c == '\t' || c == '\n')
  787.         continue;
  788.     pt = talloc(struct Status);
  789.         pt->status     = temp;
  790.         pt->revno      = sp;
  791.         pt->nextstatus = nil;
  792.     *nextstate = pt;
  793.     nextstate = &pt->nextstatus;
  794. }
  795.  
  796.  
  797.  
  798.     static void
  799. getdelrev(sp)
  800. char    *sp;
  801. /*   Function:  get revision range or branch to be deleted,     */
  802. /*              and place in delrev                             */
  803. {
  804.         int    c;
  805.         struct  delrevpair      *pt;
  806.     int separator;
  807.  
  808.     pt = &delrev;
  809.     while ((c = (*++sp)) == ' ' || c == '\n' || c == '\t')
  810.         continue;
  811.  
  812.     /* Support old ambiguous '-' syntax; this will go away.  */
  813.     if (strchr(sp,':'))
  814.         separator = ':';
  815.     else {
  816.         if (strchr(sp,'-')  &&  VERSION(5) <= RCSversion)
  817.             warn("`-' is obsolete in `-o%s'; use `:' instead", sp);
  818.         separator = '-';
  819.     }
  820.  
  821.     if (c == separator) { /* -o:rev */
  822.         while ((c = (*++sp)) == ' ' || c == '\n' || c == '\t')
  823.         continue;
  824.             pt->strt = sp;    pt->code = 1;
  825.             while( c != ' ' && c != '\n' && c != '\t' && c != '\0') c =(*++sp);
  826.             *sp = '\0';
  827.         pt->end = nil;
  828.             return;
  829.         }
  830.         else {
  831.             pt->strt = sp;
  832.             while( c != ' ' && c != '\n' && c != '\t' && c != '\0'
  833.            && c != separator )  c = *++sp;
  834.             *sp = '\0';
  835.             while( c == ' ' || c == '\n' || c == '\t' )  c = *++sp;
  836.             if ( c == '\0' )  {  /*   -o rev or branch   */
  837.                 pt->end = nil;   pt->code = 0;
  838.                 return;
  839.             }
  840.         if (c != separator) {
  841.         faterror("invalid range %s %s after -o", pt->strt, sp);
  842.             }
  843.         while ((c = *++sp) == ' ' || c == '\n' || c == '\t')
  844.         continue;
  845.         if (!c) {  /* -orev: */
  846.                 pt->end = nil;   pt->code = 2;
  847.                 return;
  848.             }
  849.         }
  850.     /* -orev1:rev2 */
  851.     pt->end = sp;  pt->code = 3;
  852.         while( c!= ' ' && c != '\n' && c != '\t' && c != '\0') c = *++sp;
  853.         *sp = '\0';
  854. }
  855.  
  856.  
  857.  
  858.  
  859.     static void
  860. scanlogtext(delta,edit)
  861.     struct hshentry *delta;
  862.     int edit;
  863. /* Function: Scans delta text nodes up to and including the one given
  864.  * by delta, or up to last one present, if delta==nil.
  865.  * For the one given by delta (if delta!=nil), the log message is saved into
  866.  * delta->log if delta==cuttail; the text is edited if EDIT is set, else copied.
  867.  * Assumes the initial lexeme must be read in first.
  868.  * Does not advance nexttok after it is finished, except if delta==nil.
  869.  */
  870. {
  871.     struct hshentry const *nextdelta;
  872.     struct cbuf cb;
  873.  
  874.     for (;;) {
  875.         foutptr = 0;
  876.         if (eoflex()) {
  877.                     if(delta)
  878.             faterror("can't find delta for revision %s", delta->num);
  879.             return; /* no more delta text nodes */
  880.                 }
  881.         nextlex();
  882.         if (!(nextdelta=getnum()))
  883.             faterror("delta number corrupted");
  884.         if (nextdelta->selector) {
  885.             foutptr = frewrite;
  886.             aprintf(frewrite,DELNUMFORM,nextdelta->num,Klog);
  887.                 }
  888.         getkeystring(Klog);
  889.         if (nextdelta == cuttail) {
  890.             cb = savestring(&curlogbuf);
  891.             if (!delta->log.string)
  892.                 delta->log = cleanlogmsg(curlogbuf.string, cb.size);
  893.         } else if (nextdelta->log.string && nextdelta->selector) {
  894.             foutptr = 0;
  895.             readstring();
  896.             foutptr = frewrite;
  897.             putstring(foutptr, false, nextdelta->log, true);
  898.             afputc(nextc, foutptr);
  899.                 } else {readstring();
  900.                 }
  901.                 nextlex();
  902.         while (nexttok==ID && strcmp(NextString,Ktext)!=0)
  903.             ignorephrase();
  904.         getkeystring(Ktext);
  905.  
  906.         if (delta==nextdelta)
  907.             break;
  908.         readstring(); /* skip over it */
  909.  
  910.     }
  911.     /* got the one we're looking for */
  912.     if (edit)
  913.         editstring((struct hshentry *)nil);
  914.     else
  915.         enterstring();
  916. }
  917.  
  918.  
  919.  
  920.     static struct Lockrev *
  921. rmnewlocklst(which)
  922.     struct Lockrev const *which;
  923. /*   Function:  remove lock to revision which->revno from newlocklst   */
  924.  
  925. {
  926.         struct  Lockrev   * pt, *pre;
  927.  
  928.         while( newlocklst && (! strcmp(newlocklst->revno, which->revno))){
  929.         struct Lockrev *pn = newlocklst->nextrev;
  930.         tfree(newlocklst);
  931.         newlocklst = pn;
  932.         }
  933.  
  934.         pt = pre = newlocklst;
  935.         while( pt ) {
  936.             if ( ! strcmp(pt->revno, which->revno) ) {
  937.                 pre->nextrev = pt->nextrev;
  938.         tfree(pt);
  939.         pt = pre->nextrev;
  940.             }
  941.             else {
  942.                 pre = pt;
  943.                 pt = pt->nextrev;
  944.             }
  945.         }
  946.         return pre;
  947. }
  948.  
  949.  
  950.  
  951.     static int
  952. doaccess()
  953. {
  954.     register struct chaccess *ch;
  955.     register struct access **p, *t;
  956.     register int changed = false;
  957.  
  958.     for (ch = chaccess;  ch;  ch = ch->nextchaccess) {
  959.         switch (ch->command) {
  960.         case erase:
  961.             if (!ch->login) {
  962.                 if (AccessList) {
  963.                 AccessList = nil;
  964.                 changed = true;
  965.                 }
  966.             } else
  967.                 for (p = &AccessList; (t = *p); p = &t->nextaccess)
  968.                 if (strcmp(ch->login, t->login) == 0) {
  969.                     *p = t->nextaccess;
  970.                     changed = true;
  971.                     break;
  972.                 }
  973.             break;
  974.         case append:
  975.             for (p = &AccessList;  ;  p = &t->nextaccess)
  976.                 if (!(t = *p)) {
  977.                     *p = t = ftalloc(struct access);
  978.                     t->login = ch->login;
  979.                     t->nextaccess = nil;
  980.                     changed = true;
  981.                     break;
  982.                 } else if (strcmp(ch->login, t->login) == 0)
  983.                     break;
  984.             break;
  985.         }
  986.     }
  987.     return changed;
  988. }
  989.  
  990.  
  991.     static int
  992. sendmail(Delta, who)
  993.     char const *Delta, *who;
  994. /*   Function:  mail to who, informing him that his lock on delta was
  995.  *   broken by caller. Ask first whether to go ahead. Return false on
  996.  *   error or if user decides not to break the lock.
  997.  */
  998. {
  999. #ifdef SENDMAIL
  1000.     char const *messagefile;
  1001.     int old1, old2, c;
  1002.         FILE    * mailmess;
  1003. #endif
  1004.  
  1005.  
  1006.     aprintf(stderr, "Revision %s is already locked by %s.\n", Delta, who);
  1007.     if (suppress_mail)
  1008.         return true;
  1009.     if (!yesorno(false, "Do you want to break the lock? [ny](n): "))
  1010.         return false;
  1011.  
  1012.         /* go ahead with breaking  */
  1013. #ifdef SENDMAIL
  1014.     messagefile = maketemp(0);
  1015.     if (!(mailmess = fopen(messagefile, "w"))) {
  1016.         efaterror(messagefile);
  1017.         }
  1018.  
  1019.     aprintf(mailmess, "Subject: Broken lock on %s\n\nYour lock on revision %s of file %s\nhas been broken by %s for the following reason:\n",
  1020.         basename(RCSname), Delta, getfullRCSname(), getcaller()
  1021.     );
  1022.     aputs("State the reason for breaking the lock:\n(terminate with single '.' or end of file)\n>> ", stderr);
  1023.  
  1024.         old1 = '\n';    old2 = ' ';
  1025.         for (; ;) {
  1026.         c = getcstdin();
  1027.         if (feof(stdin)) {
  1028.         aprintf(mailmess, "%c\n", old1);
  1029.                 break;
  1030.             }
  1031.             else if ( c == '\n' && old1 == '.' && old2 == '\n')
  1032.                 break;
  1033.             else {
  1034.         afputc(old1, mailmess);
  1035.                 old2 = old1;   old1 = c;
  1036.         if (c=='\n') aputs(">> ", stderr);
  1037.             }
  1038.         }
  1039.     Ozclose(&mailmess);
  1040.  
  1041.     if (run(messagefile, (char*)nil, SENDMAIL, who, (char*)nil))
  1042.         warn("Mail may have failed."),
  1043. #else
  1044.         warn("Mail notification of broken locks is not available."),
  1045. #endif
  1046.         warn("Please tell `%s' why you broke the lock.", who);
  1047.     return(true);
  1048. }
  1049.  
  1050.  
  1051.  
  1052.     static int
  1053. breaklock(delta)
  1054.     struct hshentry const *delta;
  1055. /* function: Finds the lock held by caller on delta,
  1056.  * and removes it.
  1057.  * Sends mail if a lock different from the caller's is broken.
  1058.  * Prints an error message if there is no such lock or error.
  1059.  */
  1060. {
  1061.     register struct lock *next, **trail;
  1062.     char const *num;
  1063.  
  1064.     num=delta->num;
  1065.     for (trail = &Locks;  (next = *trail);  trail = &next->nextlock)
  1066.         if (strcmp(num, next->delta->num) == 0) {
  1067.             if (
  1068.                 strcmp(getcaller(),next->login) != 0
  1069.                 &&    !sendmail(num, next->login)
  1070.             ) {
  1071.                 error("%s still locked by %s", num, next->login);
  1072.                 return false;
  1073.             }
  1074.             diagnose("%s unlocked\n", next->delta->num);
  1075.             *trail = next->nextlock;
  1076.             next->delta->lockedby = 0;
  1077.             return true;
  1078.                 }
  1079.     error("no lock set on revision %s", num);
  1080.     return false;
  1081. }
  1082.  
  1083.  
  1084.  
  1085.     static struct hshentry *
  1086. searchcutpt(object, length, store)
  1087.     char const *object;
  1088.     int length;
  1089.     struct hshentries *store;
  1090. /*   Function:  Search store and return entry with number being object. */
  1091. /*              cuttail = nil, if the entry is Head; otherwise, cuttail */
  1092. /*              is the entry point to the one with number being object  */
  1093.  
  1094. {
  1095.     cuthead = nil;
  1096.     while (compartial(store->first->num, object, length)) {
  1097.         cuthead = store->first;
  1098.         store = store->rest;
  1099.     }
  1100.     return store->first;
  1101. }
  1102.  
  1103.  
  1104.  
  1105.     static int
  1106. branchpoint(strt, tail)
  1107. struct  hshentry        *strt,  *tail;
  1108. /*   Function: check whether the deltas between strt and tail    */
  1109. /*        are locked or branch point, return 1 if any is  */
  1110. /*        locked or branch point; otherwise, return 0 and */
  1111. /*        mark deleted                    */
  1112.  
  1113. {
  1114.         struct  hshentry    *pt;
  1115.     struct lock const *lockpt;
  1116.  
  1117.     for (pt = strt;  pt != tail;  pt = pt->next) {
  1118.             if ( pt->branches ){ /*  a branch point  */
  1119.         error("can't remove branch point %s", pt->num);
  1120.         return true;
  1121.             }
  1122.         for (lockpt = Locks;  lockpt;  lockpt = lockpt->nextlock)
  1123.         if (lockpt->delta == pt) {
  1124.             error("can't remove locked revision %s", pt->num);
  1125.             return true;
  1126.         }
  1127.         pt->selector = false;
  1128.         diagnose("deleting revision %s\n",pt->num);
  1129.         }
  1130.     return false;
  1131. }
  1132.  
  1133.  
  1134.  
  1135.     static int
  1136. removerevs()
  1137. /*   Function:  get the revision range to be removed, and place the     */
  1138. /*              first revision removed in delstrt, the revision before  */
  1139. /*              delstrt in cuthead( nil, if delstrt is head), and the   */
  1140. /*              revision after the last removed revision in cuttail(nil */
  1141. /*              if the last is a leaf                                   */
  1142.  
  1143. {
  1144.     struct  hshentry *target, *target2, *temp;
  1145.     int length;
  1146.     int flag;
  1147.  
  1148.         flag = false;
  1149.     if (!expandsym(delrev.strt, &numrev)) return 0;
  1150.     target = genrevs(numrev.string, (char*)nil, (char*)nil, (char*)nil, &gendeltas);
  1151.         if ( ! target ) return 0;
  1152.     if (cmpnum(target->num, numrev.string)) flag = true;
  1153.     length = countnumflds(numrev.string);
  1154.  
  1155.     if (delrev.code == 0) {  /*  -o  rev    or    -o  branch   */
  1156.         if (length & 1)
  1157.         temp=searchcutpt(target->num,length+1,gendeltas);
  1158.         else if (flag) {
  1159.         error("Revision %s doesn't exist.", numrev.string);
  1160.         return 0;
  1161.         }
  1162.         else
  1163.         temp = searchcutpt(numrev.string, length, gendeltas);
  1164.         cuttail = target->next;
  1165.             if ( branchpoint(temp, cuttail) ) {
  1166.                 cuttail = nil;
  1167.                 return 0;
  1168.             }
  1169.             delstrt = temp;     /* first revision to be removed   */
  1170.             return 1;
  1171.         }
  1172.  
  1173.     if (length & 1) {   /*  invalid branch after -o   */
  1174.         error("invalid branch range %s after -o", numrev.string);
  1175.             return 0;
  1176.         }
  1177.  
  1178.     if (delrev.code == 1) {  /*  -o  -rev   */
  1179.             if ( length > 2 ) {
  1180.                 temp = searchcutpt( target->num, length-1, gendeltas);
  1181.                 cuttail = target->next;
  1182.             }
  1183.             else {
  1184.                 temp = searchcutpt(target->num, length, gendeltas);
  1185.                 cuttail = target;
  1186.                 while( cuttail && ! cmpnumfld(target->num,cuttail->num,1) )
  1187.                     cuttail = cuttail->next;
  1188.             }
  1189.             if ( branchpoint(temp, cuttail) ){
  1190.                 cuttail = nil;
  1191.                 return 0;
  1192.             }
  1193.             delstrt = temp;
  1194.             return 1;
  1195.         }
  1196.  
  1197.     if (delrev.code == 2) {   /*  -o  rev-   */
  1198.             if ( length == 2 ) {
  1199.                 temp = searchcutpt(target->num, 1,gendeltas);
  1200.                 if ( flag)
  1201.                     cuttail = target;
  1202.                 else
  1203.                     cuttail = target->next;
  1204.             }
  1205.             else  {
  1206.                 if ( flag){
  1207.                     cuthead = target;
  1208.                     if ( !(temp = target->next) ) return 0;
  1209.                 }
  1210.                 else
  1211.                     temp = searchcutpt(target->num, length, gendeltas);
  1212.         getbranchno(temp->num, &numrev);  /* get branch number */
  1213.         target = genrevs(numrev.string, (char*)nil, (char*)nil, (char*)nil, &gendeltas);
  1214.             }
  1215.             if ( branchpoint( temp, cuttail ) ) {
  1216.                 cuttail = nil;
  1217.                 return 0;
  1218.             }
  1219.             delstrt = temp;
  1220.             return 1;
  1221.         }
  1222.  
  1223.         /*   -o   rev1-rev2   */
  1224.     if (!expandsym(delrev.end, &numrev)) return 0;
  1225.     if (
  1226.         length != countnumflds(numrev.string)
  1227.         ||    length>2 && compartial(numrev.string, target->num, length-1)
  1228.     ) {
  1229.         error("invalid revision range %s-%s", target->num, numrev.string);
  1230.             return 0;
  1231.         }
  1232.  
  1233.     target2 = genrevs(numrev.string,(char*)nil,(char*)nil,(char*)nil,&gendeltas);
  1234.         if ( ! target2 ) return 0;
  1235.  
  1236.         if ( length > 2) {  /* delete revisions on branches  */
  1237.             if ( cmpnum(target->num, target2->num) > 0) {
  1238.         if (cmpnum(target2->num, numrev.string))
  1239.                     flag = true;
  1240.                 else
  1241.                     flag = false;
  1242.                 temp = target;
  1243.                 target = target2;
  1244.                 target2 = temp;
  1245.             }
  1246.             if ( flag ) {
  1247.                 if ( ! cmpnum(target->num, target2->num) ) {
  1248.             error("Revisions %s-%s don't exist.", delrev.strt,delrev.end);
  1249.                     return 0;
  1250.                 }
  1251.                 cuthead = target;
  1252.                 temp = target->next;
  1253.             }
  1254.             else
  1255.                 temp = searchcutpt(target->num, length, gendeltas);
  1256.             cuttail = target2->next;
  1257.         }
  1258.         else { /*  delete revisions on trunk  */
  1259.             if ( cmpnum( target->num, target2->num) < 0 ) {
  1260.                 temp = target;
  1261.                 target = target2;
  1262.                 target2 = temp;
  1263.             }
  1264.             else
  1265.         if (cmpnum(target2->num, numrev.string))
  1266.                     flag = true;
  1267.                 else
  1268.                     flag = false;
  1269.             if ( flag ) {
  1270.                 if ( ! cmpnum(target->num, target2->num) ) {
  1271.             error("Revisions %s-%s don't exist.", delrev.strt, delrev.end);
  1272.                     return 0;
  1273.                 }
  1274.                 cuttail = target2;
  1275.             }
  1276.             else
  1277.                 cuttail = target2->next;
  1278.             temp = searchcutpt(target->num, length, gendeltas);
  1279.         }
  1280.         if ( branchpoint(temp, cuttail) )  {
  1281.             cuttail = nil;
  1282.             return 0;
  1283.         }
  1284.         delstrt = temp;
  1285.         return 1;
  1286. }
  1287.  
  1288.  
  1289.  
  1290.     static int
  1291. doassoc()
  1292. /*   Function: add or delete(if revno is nil) association    */
  1293. /*        which is stored in assoclst            */
  1294.  
  1295. {
  1296.     char const *p;
  1297.     int changed = false;
  1298.     struct Symrev const *curassoc;
  1299.     struct assoc **pre, *pt;
  1300.  
  1301.         /*  add new associations   */
  1302.     for (curassoc = assoclst;  curassoc;  curassoc = curassoc->nextsym) {
  1303.         char const *ssymbol = curassoc->ssymbol;
  1304.  
  1305.             if ( curassoc->revno == nil ) {  /* delete symbol  */
  1306.         for (pre = &Symbols;  ;  pre = &pt->nextassoc)
  1307.             if (!(pt = *pre)) {
  1308.             warn("can't delete nonexisting symbol %s", ssymbol);
  1309.             break;
  1310.             } else if (strcmp(pt->symbol, ssymbol) == 0) {
  1311.             *pre = pt->nextassoc;
  1312.             changed = true;
  1313.             break;
  1314.             }
  1315.         }
  1316.         else {
  1317.         if (curassoc->revno[0]) {
  1318.             p = 0;
  1319.             if (expandsym(curassoc->revno, &numrev))
  1320.             p = fstr_save(numrev.string);
  1321.         } else if (!(p = tiprev()))
  1322.             error("no latest revision to associate with symbol %s",
  1323.                 ssymbol
  1324.             );
  1325.         if (p)
  1326.             changed |= addsymbol(p, ssymbol, curassoc->override);
  1327.         }
  1328.         }
  1329.     return changed;
  1330. }
  1331.  
  1332.  
  1333.  
  1334.     static int
  1335. dolocks()
  1336. /* Function: remove lock for caller or first lock if unlockcaller is set;
  1337.  *           remove locks which are stored in rmvlocklst,
  1338.  *           add new locks which are stored in newlocklst,
  1339.  *           add lock for Dbranch or Head if lockhead is set.
  1340.  */
  1341. {
  1342.     struct Lockrev const *lockpt;
  1343.     struct hshentry *target;
  1344.     int changed = false;
  1345.  
  1346.     if (unlockcaller) { /*  find lock for caller  */
  1347.             if ( Head ) {
  1348.         if (Locks) {
  1349.             switch (findlock(true, &target)) {
  1350.               case 0:
  1351.             /* remove most recent lock */
  1352.             changed |= breaklock(Locks->delta);
  1353.             break;
  1354.               case 1:
  1355.             diagnose("%s unlocked\n",target->num);
  1356.             changed = true;
  1357.             break;
  1358.             }
  1359.         } else {
  1360.             warn("No locks are set.");
  1361.         }
  1362.             } else {
  1363.         warn("can't unlock an empty tree");
  1364.             }
  1365.         }
  1366.  
  1367.         /*  remove locks which are stored in rmvlocklst   */
  1368.     for (lockpt = rmvlocklst;  lockpt;  lockpt = lockpt->nextrev)
  1369.         if (expandsym(lockpt->revno, &numrev)) {
  1370.         target = genrevs(numrev.string, (char *)nil, (char *)nil, (char *)nil, &gendeltas);
  1371.                 if ( target )
  1372.            if (!(countnumflds(numrev.string)&1) && cmpnum(target->num,numrev.string))
  1373.             error("can't unlock nonexisting revision %s",lockpt->revno);
  1374.                    else
  1375.             changed |= breaklock(target);
  1376.                         /* breaklock does its own diagnose */
  1377.             }
  1378.  
  1379.         /*  add new locks which stored in newlocklst  */
  1380.     for (lockpt = newlocklst;  lockpt;  lockpt = lockpt->nextrev)
  1381.         changed |= setlock(lockpt->revno);
  1382.  
  1383.     if (lockhead) /*  lock default branch or head  */
  1384.         if (Dbranch)
  1385.         changed |= setlock(Dbranch);
  1386.         else if (Head)
  1387.         changed |= setlock(Head->num);
  1388.         else
  1389.         warn("can't lock an empty tree");
  1390.     return changed;
  1391. }
  1392.  
  1393.  
  1394.  
  1395.     static int
  1396. setlock(rev)
  1397.     char const *rev;
  1398. /* Function: Given a revision or branch number, finds the corresponding
  1399.  * delta and locks it for caller.
  1400.  */
  1401. {
  1402.         struct  hshentry *target;
  1403.     int r;
  1404.  
  1405.     if (expandsym(rev, &numrev)) {
  1406.         target = genrevs(numrev.string, (char*)nil, (char*)nil,
  1407.                  (char*)nil, &gendeltas);
  1408.             if ( target )
  1409.            if (!(countnumflds(numrev.string)&1) && cmpnum(target->num,numrev.string))
  1410.             error("can't lock nonexisting revision %s", numrev.string);
  1411.            else {
  1412.             if ((r = addlock(target, false)) < 0  &&  breaklock(target))
  1413.             r = addlock(target, true);
  1414.             if (0 <= r) {
  1415.             if (r)
  1416.                 diagnose("%s locked\n", target->num);
  1417.             return r;
  1418.             }
  1419.            }
  1420.     }
  1421.     return 0;
  1422. }
  1423.  
  1424.  
  1425.     static int
  1426. domessages()
  1427. {
  1428.     struct hshentry *target;
  1429.     struct Message *p;
  1430.     int changed = false;
  1431.     size_t s;
  1432.  
  1433.     for (p = messagelst;  p;  p = p->nextmessage)
  1434.         if (
  1435.         expandsym(p->revno, &numrev)  &&
  1436.         (target = genrevs(
  1437.             numrev.string, (char*)0, (char*)0, (char*)0, &gendeltas
  1438.         )) &&
  1439.         (
  1440.             target->log.size != (s = p->message.size) ||
  1441.             memcmp(target->log.string, p->message.string, s) != 0
  1442.         )
  1443.         ) {
  1444.         target->log = p->message;
  1445.         changed = true;
  1446.         }
  1447.     return changed;
  1448. }
  1449.  
  1450.  
  1451.     static int
  1452. rcs_setstate(rev,status)
  1453.     char const *rev, *status;
  1454. /* Function: Given a revision or branch number, finds the corresponding delta
  1455.  * and sets its state to status.
  1456.  */
  1457. {
  1458.         struct  hshentry *target;
  1459.  
  1460.     if (expandsym(rev, &numrev)) {
  1461.         target = genrevs(numrev.string, (char*)nil, (char*)nil,
  1462.                  (char*)nil, &gendeltas);
  1463.             if ( target )
  1464.            if (!(countnumflds(numrev.string)&1) && cmpnum(target->num,numrev.string))
  1465.             error("can't set state of nonexisting revision %s to %s",
  1466.               numrev.string, status);
  1467.            else if (strcmp(target->state, status) != 0) {
  1468.                     target->state = status;
  1469.             return true;
  1470.            }
  1471.     }
  1472.     return false;
  1473. }
  1474.  
  1475.  
  1476.  
  1477.  
  1478.  
  1479.     static int
  1480. buildeltatext(deltas)
  1481.     struct hshentries const *deltas;
  1482. /*   Function:  put the delta text on frewrite and make necessary   */
  1483. /*              change to delta text                                */
  1484. {
  1485.     register FILE *fcut;    /* temporary file to rebuild delta tree */
  1486.     char const *cutname, *diffname;
  1487.  
  1488.     cutname = nil;
  1489.     cuttail->selector = false;
  1490.     scanlogtext(deltas->first, false);
  1491.         if ( cuthead )  {
  1492.         cutname = maketemp(3);
  1493.         if (!(fcut = fopen(cutname, FOPEN_W_WORK))) {
  1494.         efaterror(cutname);
  1495.             }
  1496.  
  1497.         while (deltas->first != cuthead) {
  1498.         deltas = deltas->rest;
  1499.         scanlogtext(deltas->first, true);
  1500.             }
  1501.  
  1502.         snapshotedit(fcut);
  1503.         Ofclose(fcut);
  1504.         }
  1505.  
  1506.     while (deltas->first != cuttail)
  1507.         scanlogtext((deltas = deltas->rest)->first, true);
  1508.     finishedit((struct hshentry *)nil, (FILE*)0, true);
  1509.     Ozclose(&fcopy);
  1510.  
  1511.         if ( cuthead ) {
  1512.         diffname = maketemp(0);
  1513.         switch (run((char*)nil, diffname,
  1514.             DIFF DIFF_FLAGS, cutname, resultname, (char*)nil
  1515.         )) {
  1516.         case DIFF_FAILURE: case DIFF_SUCCESS: break;
  1517.         default: faterror ("diff failed");
  1518.         }
  1519.         return putdtext(cuttail->num,cuttail->log,diffname,frewrite,true);
  1520.     } else
  1521.         return putdtext(cuttail->num,cuttail->log,resultname,frewrite,false);
  1522. }
  1523.  
  1524.  
  1525.  
  1526.     static void
  1527. buildtree()
  1528. /*   Function:  actually removes revisions whose selector field  */
  1529. /*        is false, and rebuilds the linkage of deltas.     */
  1530. /*              asks for reconfirmation if deleting last revision*/
  1531. {
  1532.     struct    hshentry   * Delta;
  1533.         struct  branchhead      *pt, *pre;
  1534.  
  1535.         if ( cuthead )
  1536.            if ( cuthead->next == delstrt )
  1537.                 cuthead->next = cuttail;
  1538.            else {
  1539.                 pre = pt = cuthead->branches;
  1540.                 while( pt && pt->hsh != delstrt )  {
  1541.                     pre = pt;
  1542.                     pt = pt->nextbranch;
  1543.                 }
  1544.                 if ( cuttail )
  1545.                     pt->hsh = cuttail;
  1546.                 else if ( pt == pre )
  1547.                     cuthead->branches = pt->nextbranch;
  1548.                 else
  1549.                     pre->nextbranch = pt->nextbranch;
  1550.             }
  1551.     else {
  1552.             if ( cuttail == nil && !quietflag) {
  1553.         if (!yesorno(false, "Do you really want to delete all revisions? [ny](n): ")) {
  1554.             error("No revision deleted");
  1555.             Delta = delstrt;
  1556.             while( Delta) {
  1557.             Delta->selector = true;
  1558.             Delta = Delta->next;
  1559.             }
  1560.             return;
  1561.         }
  1562.         }
  1563.             Head = cuttail;
  1564.     }
  1565.         return;
  1566. }
  1567.  
  1568. #if RCS_lint
  1569. /* This lets us lint everything all at once. */
  1570.  
  1571. char const cmdid[] = "";
  1572.  
  1573. #define go(p,e) {int p P((int,char**)); void e P((void)); if(*argv)return p(argc,argv);if(*argv[1])e();}
  1574.  
  1575.     int
  1576. main(argc, argv)
  1577.     int argc;
  1578.     char **argv;
  1579. {
  1580.     go(ciId,    ciExit);
  1581.     go(coId,    coExit);
  1582.     go(identId,    identExit);
  1583.     go(mergeId,    mergeExit);
  1584.     go(rcsId,    exiterr);
  1585.     go(rcscleanId,    rcscleanExit);
  1586.     go(rcsdiffId,    rdiffExit);
  1587.     go(rcsmergeId,    rmergeExit);
  1588.     go(rlogId,    rlogExit);
  1589.     return 0;
  1590. }
  1591. #endif
  1592.